package com.china.produce.config.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/8/7
 */
@Configuration
public class TopicConfig {

    /**
     * 声明死信队列
     *
     * @return
     */
    @Bean
    public Queue deadQueue() {

        HashMap<String, Object> args = new HashMap<>();

        args.put("x-dead-letter-exchange", "dead_topic_exchange");
        args.put("x-dead-letter-routing-key", "topic.msg");
        args.put("x-message-ttl", 15000);

        return new Queue("dead.queue", true, false, false, args);
    }

    /**
     * 申明死信交换机
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {

        return new TopicExchange("topic_exchange", true, false);
    }

    /**
     * 队列绑定交换机
     *
     * @return
     */
    @Bean
    public Binding bindQueueToExchange() {

        return BindingBuilder.bind(deadQueue()).to(topicExchange()).with("topic.*");
    }


    @Bean
    public TopicExchange dealTopicExchange() {

        return new TopicExchange("deal_topic_exchange", true, false);
    }

    @Bean
    public Queue dealQueue() {

        return new Queue("deal.queue", true, false, false);
    }

    @Bean
    public Binding bindingDealQueueToExchange() {
        return BindingBuilder.bind(dealQueue()).to(dealTopicExchange()).with("deal.*");
    }
}
